<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/vue.js"></script>
</head>
<template id="cpn_id">
    <div>
        <button v-on:click="btnClick">按钮</button>
    </div>
</template>
<body>
<div id="div_id">
    <cpn v-bind:msg="message"></cpn>
</div>
<script>
    const  app=new Vue({
        el:"#div_id",
        data:{
          message:'这是父组件的数据'
        },
        components:{
            cpn:{
                template:"#cpn_id",
                props:{
                  msg:{
                      type:String,
                      default:''
                  }
                },
                methods:{
                    btnClick(){
                        //父组件
                        console.log(this.$parent.message);
                        //根组件
                        console.log(this.$root.message);
                    }
                }
            }
        }
    })
</script>
</body>
</html>